package pages;

import core.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import tests.TestData;
import utils.Log4Test;
import java.util.List;



/**
 * Created by Nicktoris on 22.07.2014.
 */
public class AllNoteBooksPage extends TestBase
{

    public List<WebElement> allManufacturesList()
    {
        List<WebElement> list = webDriver.findElements(By.xpath("//div[2]/div[3]//li[2]/ul/li"));
        if (list.size()>0)
        {
            Log4Test.info("List of Manufactures is found. At least one is present");
            return list;
        }
        else
        {
            Log4Test.info("List of Manufactures is empty");
            return list;

        }
    }

    public WebElement verifyNoteBooksTabIsActive()
    {

        Log4Test.info("Verify if NoteBooks tab is active");
        WebElement activeNoteBookTab = webDriver.findElement(By.xpath("//*[@id='computers-notebooks']/div[@class='m-main-i active']"));
        return activeNoteBookTab;
    }

    public int countManufacturers()
    {
        Log4Test.info("The page has "+ allManufacturesList().size()+ " manufacturers" );
        return allManufacturesList().size();
    }

    public void clickApple()
    {
        for (WebElement element: allManufacturesList())
        {
            if (element.getText().contains("Apple"))
            {
                targetElement = webDriver.findElement(By.xpath(".//*[@id='head_banner_container']/div[4]/div/div/div[2]/div[3]/ul/li[2]/ul/li[2]/a"));



            }

        }
        targetElement.click();
        Log4Test.info("The Apple manufacturer was found. Navigating to Apple nootebooks page... ");
    }


}
